import { IRegistrationBuilder } from "../Interfaces/IIOC";
/**
 * IOC 构造器
 */
export class RegistrationBuilder implements IRegistrationBuilder {
  builderList: IRegistrationBuilder[];
  ifName: string;
  classType: Function;
  isInstance: boolean;
  private _transferData: any;
  get transferData(): any {
    if (this.isInstance) {
      return this._transferData;
    } else {
      return this.getClassData();
    }
  }
  set transferData(data: any) {
    this._transferData = data;
  }

  constructor(ifname: string, classtype: Function) {
    this.ifName = ifname;
    this.classType = classtype;
  }
  AS(): IRegistrationBuilder {
    return this;
  }
  Named(serviceName: string): IRegistrationBuilder {
    this.ifName = serviceName;
    return this;
  }
  SingleInstance(): IRegistrationBuilder {
    this.isInstance = true;
    this.transferData = this.getClassData();
    return this;
  }
  private getClassData(): any {
    return new this.classType.prototype.constructor();
  }
}
